package gps.util;


public class GraphHelper {
	/*
	public static WeightedGraph<PositionSquare,DefaultWeightedEdge> generateGraph(Square[][] matrix) {
		EdgeFactory<PositionSquare, DefaultWeightedEdge> efactory = new ClassBasedEdgeFactory<PositionSquare, DefaultWeightedEdge>(DefaultWeightedEdge.class);
		WeightedGraph<PositionSquare, DefaultWeightedEdge> graph = new SimpleWeightedGraph<PositionSquare, DefaultWeightedEdge>(efactory);
		PositionSquare[][] matrixWithPositions = new PositionSquare[matrix.length][matrix.length];
		
		for (int i = 0 ; i < Parameters.BOARD_SIZE ; i++ ){
			for (int j = 0 ; j < Parameters.BOARD_SIZE ; j++ ){
				matrixWithPositions[i][j] = new PositionSquare(matrix[i][j].getColour(), i, j);
				graph.addVertex(matrixWithPositions[i][j]);
			}
		}
		
		for (int i = 0 ; i < Parameters.BOARD_SIZE ; i++ ){
			for (int j = 0 ; j < Parameters.BOARD_SIZE ; j++ ){
				if (i!=0){
					addEdgeExtended(graph, matrixWithPositions[i][j],matrixWithPositions[i-1][j]);
				}
				if (i!=Parameters.BOARD_SIZE-1){
					addEdgeExtended(graph, matrixWithPositions[i][j],matrixWithPositions[i+1][j]);
				}
				if (j!=0){
					addEdgeExtended(graph, matrixWithPositions[i][j],matrixWithPositions[i][j-1]);
				}
				if (j!=Parameters.BOARD_SIZE-1){
					addEdgeExtended(graph, matrixWithPositions[i][j],matrixWithPositions[i][j+1]);
				}
			}
		}
		
		return graph;
	}
	
	private static void addEdgeExtended(WeightedGraph<PositionSquare, DefaultWeightedEdge> graph, PositionSquare sq1, PositionSquare sq2){
		graph.addEdge(sq1,sq2);
		graph.setEdgeWeight(graph.getEdge(sq1, sq2), edgeValue(sq1,sq2));
	}
	
	private static double edgeValue(PositionSquare sq1, PositionSquare sq2){
		if (sq1.getColour().equals(sq2.getColour())){
			return 0;
		}else{
			return 1;
		}
	}
	
	public static PositionSquare getTopLeft(WeightedGraph<PositionSquare, DefaultWeightedEdge> graph){
		for (PositionSquare s : graph.vertexSet()){
			if (s.getX()==0 && s.getY()==0){
				return s;
			}
		}
		return null;
	}
	
	public static PositionSquare getBottomRight(WeightedGraph<PositionSquare, DefaultWeightedEdge> graph){
		for (PositionSquare s : graph.vertexSet()){
			if (s.getX()==Parameters.BOARD_SIZE-1 && s.getY()==Parameters.BOARD_SIZE-1){
				return s;
			}
		}
		return null;
	}
	*/	
}
